<template>
  <div class="mod-config">
    <basic-container>
      <navigation
        :sign="{ a: false, b: false, c: false, d: true, e: true }"
      ></navigation>
      <div v-if="ymLoad" class="duiQitishi">
        <div class="tiShiTu">
          <img src="/images/qita/tishi.png" width="300" />
        </div>
        <div class="tiShi">
          <div>
            <b>您现在不是任何部门的奖金管理人员，无法进行奖金分配发放的操作</b>
          </div>
          <div class="font18 mt10">
            您可以通知系统管理员，为您设置具体的奖金管理部门！
          </div>
        </div>
      </div>
      <div class="boxsty zhiBiao" v-else>
        <el-form
          :inline="true"
          :model="dataForm"
          @keyup.enter.native="getDataList()"
          class="form-inline"
        >
          <el-form-item label="负责部门">
            <el-select
              v-model="deptId"
              placeholder="请选择负责部门"
              class="xiaLa"
              style="width: 300px"
              :clearable="true"
              @change="switchDepartment"
            >
              <el-option
                v-for="(item, index) in fzbmData"
                :key="index"
                :label="item.deptName"
                :value="item.deptId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="奖金名称">
            <el-input
              v-model="dataForm.jjMc"
              placeholder="奖金名称"
              :clearable="true"
            ></el-input>
          </el-form-item>
          <el-form-item label="审核状态">
            <el-select
              v-model="dataForm.fpZt"
              placeholder="请选择"
              :clearable="true"
            >
              <el-option value="分配中" label="分配中"></el-option>
              <el-option value="审批中" label="审批中"></el-option>
              <el-option value="调整中" label="调整中"></el-option>
              <el-option value="审批通过" label="审批通过"></el-option>
              <el-option value="人员已分配" label="人员已分配"></el-option>
              <el-option value="没有分配" label="没有分配"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="月份">
            <el-date-picker
            v-model="dataForm.months"
            type="month"
            value-format="MM"
            format="MM"
            placeholder="选择月">
          </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button
              icon="el-icon-search"
              type="primary"
              class="marginLeft"
              v-if="deptbz"
              @click="getDataList(1)"
              plain
              >检索
            </el-button>
          </el-form-item>
        </el-form>
        <div
          style="
            padding-bottom: 10px;
            display: flex;
            justify-content: space-between;
          "
        >
          <div>
            <el-tooltip
              class="item"
              effect="dark"
              :content="jrContent"
              placement="top-start"
              v-model="isShow"
            >
              <el-button
                icon="el-icon-plus"
                v-if="permissions.jiangjin_jiangjinfpjjfpdjb_add && deptbz"
                :type="jrType"
                @click="addOrUpdateHandleTwo()"
                circle
              >
              </el-button>
            </el-tooltip>
            <!-- <el-tooltip
              class="item"
              effect="dark"
              content="固定月奖分配"
              placement="top"
            >
              <el-button
                icon="el-icon-plus"
                v-if="permissions.jiangjin_jiangjinfpjjfpdjb_add && deptbz"
                type="success"
                @click="openYdjj()"
                circle
              >
              </el-button>
            </el-tooltip> -->
            <el-tooltip
              class="item"
              effect="dark"
              content="删除"
              placement="top"
            >
              <el-button
                icon="el-icon-delete"
                v-if="permissions.jiangjin_jiangjinfpjjfpdjb_del"
                type="danger"
                @click="deleteHandle()"
                circle
              >
              </el-button>
            </el-tooltip>
          </div>
          <div>
            <!-- <el-button
              icon="el-icon-upload"
              type="info"
              class="marginLeft"
              @click="importjjBtn()"
              plain
              >奖金导入
            </el-button> -->
            <el-button
              icon="el-icon-finished"
              type="success"
              class="marginLeft"
              v-if="permissions.jiangjin_jiangjinfpjjfpdjb_add"
              @click="xinJiangTwo"
              plain
              >奖金分配
            </el-button>
            <el-button
              icon="el-icon-coin"
              type="primary"
              class="marginLeft"
              v-if="deptbz"
              @click="openJjc()"
              plain
              >机构奖金池
            </el-button>
            <el-button
              icon="el-icon-coin"
              type="warning"
              class="marginLeft"
              v-if="deptbz"
              @click="jjcManage()"
              plain
              >奖金池管理
            </el-button>
          </div>
        </div>
        <el-table
          :data="dataList"
          v-loading="dataListLoading"
          ref="table"
          border
          stripe
          min-height="50vh"
          style="margin-top: 10px"
        >
          <el-table-column
            type="selection"
            width="55">
          </el-table-column>
          <!--          <el-table-column prop="" type="index" min-width="80" width="80" label="序号" :formatter="nShowIndex"></el-table-column>-->
          <el-table-column
            prop=""
            label="序号"
            :formatter="nShowIndex"
            width="80"
            header-align="center"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="jjMc"
            label="奖金名称"
            show-overflow-tooltip
            min-width="200"
            header-align="center"
            align="center"
          >
          <template slot-scope="scope">
            <span v-if="tabType=='jigou'&&scope.row.importflag==1&&scope.row.pid==0" @click="faqiDetail(scope.row)" style="color:#0e258c;cursor: pointer;">{{scope.row.jjMc}}</span>
            <span v-else-if="tabType=='jigou'&&scope.row.pid==0&&scope.row.importflag!=1" @click="jigouTan(scope.row.id)" style="color:#0e258c;cursor: pointer;">{{scope.row.jjMc}}</span>
            <span v-else-if="scope.row.pid!=0&&scope.row.importflag!=1"  @click="renyuanTan(scope.row.id)" style="color:#0e258c;cursor: pointer;">{{scope.row.jjMc}}</span>
            <span v-else >{{scope.row.jjMc}}</span>
          </template>
          </el-table-column>
          <el-table-column
            prop="jjDeptName"
            label="负责部门"
            min-width="200"
            header-align="center"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="jjZe"
            label="奖金总额(元)"
            header-align="center"
            align="right"
            min-width="115"
          >
            <template slot-scope="scope">
              <div v-if="scope.row.tableData">
                <el-popover v-if="scope.row.tableData.length>0" placement="top" width="300" trigger="hover">
                  <el-table :data="scope.row.tableData" max-height="400">
                      <el-table-column
                        min-width="100"
                        label="奖金名称"
                      >
                        <template slot-scope="scope">
                            <span>{{scope.row.label}}</span>
                        </template>
                      </el-table-column>
                      <el-table-column
                        min-width="100"
                        label="奖金金额"
                      >
                        <template slot-scope="scope">
                            <span>{{scope.row.prop}}</span>
                        </template>
                      </el-table-column>
                  </el-table>
                  <span slot="reference">{{ $formatNum(scope.row.jjZe) }}</span>
                </el-popover>
                <span v-else>{{ $formatNum(scope.row.jjZe)}}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="fpZe"
            label="使用金额"
            header-align="center"
            align="right"
            min-width="115">
            <template slot-scope="scope">
              <span v-if="tabType=='jigou'">
                  <span v-if="scope.row.jjZe-scope.row.fpZe!=0" style="color:#ff3300">{{ $formatNum(scope.row.fpZe)}}</span>
                  <span v-else>{{ $formatNum(scope.row.fpZe)}}</span>
              </span>
              <span v-else>
                  <span v-if="scope.row.jjZe-scope.row.ygJj!=0" style="color:#ff3300">{{ $formatNum(scope.row.ygJj)}}</span>
                  <span v-else>{{ $formatNum(scope.row.ygJj)}}</span>
              </span>
            </template>
          </el-table-column>
          <el-table-column
            prop="jjYe"
            label="奖金余额(元)"
            header-align="center"
            align="right"
            min-width="115">
            <template slot-scope="scope">
              <span v-if="scope.row.jjYe>0" style="color:#ff3300">{{ $formatNum(scope.row.jjYe) }}</span>
              <span v-else>{{ $formatNum(scope.row.jjYe) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="fpZt"
            label="分配状态"
            header-align="center"
            align="center"
            min-width="100"
          >
            <template slot-scope="scope">
                  <el-popover placement="top" width="660" trigger="hover" v-if="scope.row.processId">
                    <el-table :data="scope.row.gridData" max-height="400" v-if="scope.row.gridData && scope.row.gridData.length != 0">
                      <el-table-column
                        width="260"
                        property="NAME_"
                        label="任务名称"
                        show-overflow-tooltip
                      ></el-table-column>
                      <el-table-column
                        width="120"
                        property="ry_name"
                        label="处理人"
                        show-overflow-tooltip
                      ></el-table-column>
                      <el-table-column
                        width="120"
                        property="START_TIME_"
                        label="开始时间"
                        show-overflow-tooltip
                      ></el-table-column>
                      <el-table-column
                        width="120"
                        property="END_TIME_"
                        label="结束时间"
                        show-overflow-tooltip
                      ></el-table-column>
                    </el-table>
                    <span slot="reference" v-if="scope.row.jjLx == 2"></span>
                    <span slot="reference"
                      :class="Zt(scope.row.fpZt)"
                      v-else-if="scope.row.bmJj > 0||scope.row.jjcJe>0"
                      >{{ scope.row.fpZt }}</span
                    >
                    <span slot="reference" v-else-if="scope.row.processIdFf">人员已分配</span>
                    <span slot="reference" v-else>没有分配</span>
                    <el-button
                      type="primary"
                      icon="el-icon-search"
                      v-if="scope.row.processId != '' && scope.row.processId != null"
                      @click="showMessage(scope.row.processId)"
                      >流程跟踪</el-button>
                  </el-popover>
                  <span slot="reference" v-else>非机构分配</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="fpZt"
            label="返回状态"
            header-align="center"
            align="center"
            min-width="100"
          >
            <template slot-scope="scope">
                  <el-popover  v-if="(scope.row.processIdFf != '' && scope.row.processIdFf != null)" placement="top" width="260" trigger="hover">
                    <el-button
                      type="primary"
                      icon="el-icon-search"
                      @click="showMessage(scope.row.processIdFf)"
                      >流程跟踪</el-button
                    >
                  <span slot="reference" :class="Zt(scope.row.ffZt)">
                      {{
                      scope.row.ffZt
                    }}</span>
                  </el-popover>
                <span slot="reference" :class="Zt(scope.row.ffZt)" v-else-if="scope.row.bmJj == 0 && scope.row.jjcJe==0">{{
                    scope.row.ffZt
                  }}</span>
                  <span slot="reference" v-else-if="!scope.row.ffZt"> 等待分配 </span>
                  <el-popover  v-else-if="scope.row.bmSl != scope.row.bmFfspSl" placement="top" width="660" trigger="hover">
                    <el-table :data="scope.row.ffspData" max-height="400">
                      <el-table-column
                        mi-width="260"
                        property="jgmc"
                        label="机构名称"
                        show-overflow-tooltip
                      ></el-table-column>
                      <el-table-column
                        width="120"
                        property="sfjj"
                        label="实际下发金额"
                        show-overflow-tooltip
                      ></el-table-column>
                      <el-table-column
                        width="120"
                        property="yfjj"
                        label="已发金额"
                        show-overflow-tooltip
                      >
                      <template  slot-scope="scope1">
                          <span v-if="scope1.row.yfjj*1!=scope1.row.sfjj*1" style="color:#ff3300">{{scope1.row.yfjj}}</span>
                          <span v-else>{{scope1.row.yfjj}}</span>
                      </template>
                      </el-table-column>
                    </el-table>
                    <span slot="reference">{{ scope.row.bmFfspSl }}/{{ scope.row.bmSl }}</span>
                  </el-popover>

                  <span slot="reference" :class="Zt(scope.row.ffZt)" v-else>
                    {{
                    scope.row.ffZt
                  }}</span>
                <!-- <el-button
                  type="primary"
                  icon="el-icon-search"
                  v-if="scope.row.processIdFf != '' && scope.row.processIdFf != null"
                  @click="showMessage(scope.row.processIdFf)"
                  >流程跟踪</el-button
                > -->

            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            header-align="center"
            align="center"
            min-width="80"
          >
            <template slot-scope="scope">
              <el-dropdown>
                <span class="el-dropdown-link">
                  <el-button type="primary" plain icon="el-icon-arrow-down"
                    >更多</el-button
                  >
                </span>
                <el-dropdown-menu slot="dropdown">
                  <!--修改分配-->
                  <!-- <el-dropdown-item
                    v-if="
                      permissions.jiangjin_jiangjinfpjjfpdjb_edit &&
                      scope.row.fpLy == 2 &&
                      scope.row.bmJj == 0 &&
                      scope.row.ygJj == 0 &&
                      scope.row.fpZt == '分配中' &&
                      scope.row.hfStatus==0
                    "
                    type="primary"
                    plain
                    @click.native="addOrUpdateHandle(scope.row.id)"
                    >修改分配
                  </el-dropdown-item> -->
                  <!--确认发放月奖-->
                  <el-dropdown-item
                    v-if="
                      permissions.jiangjin_jiangjinfpjjfpdjb_add &&
                      scope.row.jjLx == 2 &&
                      scope.row.fpZt == '分配中' &&
                      scope.row.ffZt == null
                    "
                    type="primary"
                    plain
                    @click.native="dataFormSubmit(scope.row.id)"
                    >确认发放月奖
                  </el-dropdown-item>
                  <!--有部门分配才有分配提审 并且分配等于分配中 ok   -->
                  <el-dropdown-item
                    v-if="
                      permissions.jiangjin_jiangjinfpjjfpdjb_add &&
                      (scope.row.bmJj > 0 || scope.row.jjcJe)&&
                      scope.row.fpZt == '分配中'
                    "
                    type="primary"
                    plain
                    @click.native="tsJjfp(scope.row, 'fpts')"
                    >提交审核
                  </el-dropdown-item>
                  <!--调整中提交-->
                  <el-dropdown-item
                    v-if="
                      permissions.jiangjin_jiangjinfpjjfpdjb_add &&
                      scope.row.ffZt == '调整中' || scope.row.fpZt == '调整中'
                    "
                    type="primary"
                    plain
                    @click.native="dzti(scope.row, 'dztj')"
                    >提交
                  </el-dropdown-item>
                  <!--分配等于审批中或审批通过 ok  -->
                  <el-dropdown-item
                    v-if="
                      permissions.jiangjin_jiangjinfpjjfpdjb_add &&
                      (scope.row.fpZt == '审批中' ||
                        scope.row.fpZt == '审批通过') &&
                      scope.row.mainId
                    "
                    type="primary"
                    plain
                    @click.native="viewJjfp(scope.row)"
                    >分配详情
                  </el-dropdown-item>
                  <!--只有员工分配就只有发放审批 并且发放等于分配中或空 有部门分配并且所有分配部门发放审批通过才能进行发放审批 分配等于审批通过 发放等于分配中  -->
                  <el-dropdown-item
                    v-if="
                      permissions.jiangjin_jiangjinfpjjfpdjb_add &&
                      ((scope.row.bmJj == 0 &&
                        scope.row.ygJj > 0 &&
                        scope.row.ffZt != '审批中' && scope.row.ffZt != '调整中' &&
                        scope.row.ffZt != '审批通过'&& scope.row.ffZt!='上级审批中'&& scope.row.ffZt!='上级领导审批中'&& scope.row.ffZt!='审批完成') ||
                        (scope.row.bmJj > 0 &&
                          scope.row.bmSl > 0 &&
                          scope.row.bmSl == scope.row.bmFfspSl &&
                          scope.row.ffZt != '审批中' && scope.row.ffZt != '调整中' &&
                          scope.row.ffZt != '审批通过'&& scope.row.ffZt!='上级审批中'&& scope.row.ffZt!='上级领导审批中'&& scope.row.ffZt!='审批完成' )||
                        (scope.row.bmJj == 0 &&
                          scope.row.jjcJe > 0 &&
                          scope.row.ffZt != '审批中' && scope.row.ffZt != '调整中' &&
                          scope.row.ffZt != '审批通过'&& scope.row.ffZt!='上级审批中'&& scope.row.ffZt!='上级领导审批中'&& scope.row.ffZt!='审批完成' ))
                    "
                    type="primary"
                    plain
                    @click.native="tsJjff(scope.row, 'ffts')"
                    >发放提审
                  </el-dropdown-item>
                  <!--发放等于审批中或审批通过  ok -->
                  <el-dropdown-item
                    v-if="
                      permissions.jiangjin_jiangjinfpjjfpdjb_add &&
                      (scope.row.ffZt == '审批中' ||
                        scope.row.ffZt == '审批通过') &&
                      scope.row.mainIdFf
                    "
                    type="primary"
                    plain
                    @click.native="viewJjff(scope.row)"
                    >发放详情
                  </el-dropdown-item>
                  <!--分配等于审批通过发放不等于审批通过  ok && scope.row.ffZt == '发放中'-->
                  <el-dropdown-item
                    v-if="
                      permissions.jiangjin_jiangjinfpjjfpdjb_add &&
                      (scope.row.fpZt == '审批通过' || scope.row.fpZt == '审批中') && scope.row.ffZt!='上级审批中'&& scope.row.ffZt!='上级领导审批中'&& scope.row.ffZt!='审批完成'

                    "
                    type="primary"
                    plain
                    @click.native="viewHffp(scope.row)"
                    >恢复分配
                  </el-dropdown-item>
                  <!--分配不等于审批中、审批通过发放不等于审批中、审批通过 ok  最原始-->
                  <!-- <el-dropdown-item
                    v-if="
                      permissions.jiangjin_jiangjinfpjjfpdjb_add &&
                      scope.row.fpZt == '分配中' &&
                      !(
                        scope.row.ffZt == '审批中' ||
                        scope.row.ffZt == '审批通过'
                      ) && scope.row.jjLx != 2
                    "
                    type="primary"
                    plain
                    @click.native="openJjfp(scope.row.id)"
                    >分配操作
                  </el-dropdown-item> -->
                  <!--发放等于审批通过  ok -->
                  <el-dropdown-item
                    v-if="scope.row.ffZt == '审批通过'||scope.row.ffZt == '上级领导审批中'||scope.row.ffZt == '审批完成'||scope.row.ffZt == '上级审批中'"
                    type="primary"
                    plain
                    @click.native="openJjff(scope.row)"
                    >详情查看
                  </el-dropdown-item>
                  <!-- <el-dropdown-item
                    v-if="
                      permissions.jiangjin_jiangjinfpjjfpdjb_add &&
                      scope.row.fpZt == '分配中' &&
                      scope.row.ffZt == null &&
                      scope.row.ygJj == 0 &&
                      scope.row.bmJj == 0 &&
                      scope.row.ygJj == 0 &&
                      scope.row.pid != 0 &&
                      scope.row.jjxList.length > 1
                    "
                    type="danger"
                    plain
                    @click.native="fenjieHandle(scope.row)"
                    >任务分解
                  </el-dropdown-item>
                  <el-dropdown-item
                    v-if="
                      permissions.jiangjin_jiangjinfpjjfpdjb_del &&
                      scope.row.fpZt == '分配中' &&
                      !(
                        scope.row.ffZt == '审批中' ||
                        scope.row.ffZt == '审批通过'
                      ) &&
                      scope.row.pid == 0
                    "
                    type="danger"
                    plain
                    @click.native="deleteHandle(scope.row.id)"
                    >删除
                  </el-dropdown-item>-->
                  <el-dropdown-item
                    type="primary"
                    plain
                    v-if="scope.row.ffZt!='上级审批中'"
                    @click.native="fjgl(scope.row.id)"
                    >附件管理
                  </el-dropdown-item>
                  <el-dropdown-item
                    type="primary"
                    plain
                    v-if="scope.row.ffZt=='上级审批中'"
                    @click.native="onPass(scope.row,'通过')"
                    >通过
                  </el-dropdown-item>
                  <el-dropdown-item
                    type="primary"
                    plain
                    v-if="scope.row.ffZt=='上级审批中'"
                    @click.native="onRejected(scope.row,'驳回')"
                    >驳回
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </el-table-column>
        </el-table>

        <div class="avue-crud__pagination">
          <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :current-page="pageIndex"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageSize"
            :total="totalPage"
            background
            layout="total, sizes, prev, pager, next, jumper"
          >
          </el-pagination>
        </div>
      </div>
      <el-dialog
        title="奖金分配提请审批"
        :close-on-click-modal="false"
        :visible.sync="fpspvisible"
        width="600px"
      >
        <el-form :model="formfp" ref="fpform" label-width="120px">
          <el-form-item
            label="审批流程："
            prop="examineId"
            :rules="[{ required: true, message: '请选择审批流程' }]"
          >
            <el-select
              v-model="formfp.examineId"
              placeholder="请选择审批流程"
              style="width: 70%"
            >
              <el-option
                v-for="(t, i) in wfListfp"
                :label="t.flowName"
                :value="t.id"
                :key="i"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="tjfpsptj()">提交审批</el-button>
          <el-button @click="fpspvisible = false">取消</el-button>
        </span>
      </el-dialog>
      <el-dialog
        title="奖金发放提请审批"
        :close-on-click-modal="false"
        :visible.sync="ffspvisible"
        width="600px"
      >
        <el-form :model="formff" ref="ffform" label-width="120px">
          <el-form-item
            label="审批流程："
            prop="examineId"
            :rules="[{ required: true, message: '请选择审批流程' }]"
          >
            <el-select
              v-model="formff.examineId"
              placeholder="请选择审批流程"
              style="width: 70%"
            >
              <el-option
                v-for="(t, i) in wfListff"
                :label="t.flowName"
                :value="t.id"
                :key="i"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">

          <el-button type="primary" @click="tjffsptj()">提交审批</el-button>
          <el-button @click="ffspvisible = false">取消</el-button>
        </span>
      </el-dialog>
      <!-- 弹窗, 新增 / 修改 -->
      <table-form
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        @refreshDataList="getDataList"
      ></table-form>
      <table-form-two
        v-if="addOrUpdateVisibleTwo"
        ref="addOrUpdateTwo"
        @refreshDataList="getDataList"
      ></table-form-two>
      <!-- 弹窗, 奖金分配 -->
      <jiangjinfpjjfpdjbFp
        ref="jiangjinfpjjfpdjbFp"
        @refreshDataList="getDataList"
      ></jiangjinfpjjfpdjbFp>
      <jiangjinfpjjfpdjbFf
        ref="jiangjinfpjjfpdjbFf"
        @refreshDataList="getDataList"
      ></jiangjinfpjjfpdjbFf>
      <!-- 机构奖金池 -->
      <table-form-jjc
        v-if="tableFormJjcVisible"
        ref="tableFormJjc"
      ></table-form-jjc>
      <!-- 奖金池管理 -->
      <table-form-jjc-gl
        v-if="tableFormJjcGlVisible"
        ref="tableFormJjcGl"
      ></table-form-jjc-gl>
      <!-- 弹窗, 奖金分配 -->
      <workflow ref="workflow" @refreshDataList="getDataList"></workflow>
      <jiangjinWork ref="jiangjinWork"></jiangjinWork>
      <!-- 弹窗, 月度分配 -->
      <jiangjinfpjjfpdjbYdjjForm
        ref="jiangjinfpjjfpdjbYdjjForm"
        @refreshDataList="getDataList"
      ></jiangjinfpjjfpdjbYdjjForm>
      <!-- 弹窗, 分解 -->
      <jiangjinfpjjfpdjbRwfjForm
        ref="jiangjinfpjjfpdjbRwfjForm"
        @refreshDataList="getDataList"
      ></jiangjinfpjjfpdjbRwfjForm>
      <!-- 弹窗, 恢复分配 -->
      <jiangjinfpjjfpdjbHffpForm
        ref="jiangjinfpjjfpdjbHffpForm"
        @refreshDataList="getDataList"
      ></jiangjinfpjjfpdjbHffpForm>
      <!-- 弹窗, 恢复分配（新） -->
      <jiangjinfpjjfpdjbHffpNew
        ref="jiangjinfpjjfpdjbHffpNew"
        @refreshDataList="getDataList"
      ></jiangjinfpjjfpdjbHffpNew>
      <jiangjinfpjjfpdjbHffpForm
        ref="jiangjinfpjjfpdjbHffpForm"
        @refreshDataList="getDataList"
      ></jiangjinfpjjfpdjbHffpForm>
      <!--新的奖金分配-->
      <jiangjinxinfpryfz
        ref="jiangjinxinfpryfzForm"
        @refreshDataList="getDataList"
      ></jiangjinxinfpryfz>
      <!--最新奖金分配-->
      <fpcaozuo ref="fpcaozuoRef" @refreshDataList="getDataList"></fpcaozuo>
      <jiangjinfpjjfpdjbFileManager
        ref="jiangjinfpjjfpdjbFileManager"
      ></jiangjinfpjjfpdjbFileManager>
      <!-- 提审选人 -->
      <personCard
        ref="usercomment"
        :isJjfp="isJjfp"
        @submitfy="submitfy"
      ></personCard>
      <el-dialog :visible.sync="showPicDialog" title="流程图" width="100%">
        <div>
          <el-row>
            <el-col :span="12">
              <el-image
                v-if="showPicDialog"
                :headers="headers"
                :src="actPicUrl"
                :preview-src-list="actPicUrlList"
                width="100%"
                class="bg"
              ></el-image>
            </el-col>
            <el-col :span="12"
              ><el-table :data="hisTableData" border style="width: 100%">
                <el-table-column prop="taskId" label="任务ID" width="100">
                </el-table-column>
                <el-table-column
                  prop="processInstanceId"
                  label="流程实例ID"
                  width="100"
                >
                </el-table-column>
                <el-table-column prop="taskName" label="任务名称">
                </el-table-column>
                <el-table-column prop="assignee" label="处理人">
                  <template slot-scope="scope">
                    <span>{{ scope.row.assignee }}</span>
                  </template>
                </el-table-column>
                <el-table-column prop="start" label="开始时间"> </el-table-column>
                <el-table-column prop="end" label="结束时间">
                </el-table-column> </el-table
            ></el-col>
          </el-row>
        </div>
      </el-dialog>
      <jjimportDiaolg :importjjDiaolgData="importjjDiaolgData"></jjimportDiaolg>
    </basic-container>
    <processTracking
      ref="processTracking"
      @processTrackingChildren="getDataList"
    ></processTracking>
    <!--机构计算结果-->
    <el-dialog
      title="分配计算"
      :visible.sync="mninnerVisible"
      append-to-body
      :fullscreen="false"
    >
      <jigouResults ref="jigouResults"></jigouResults>
    </el-dialog>
    <!--人员计算结果-->
    <el-dialog
      title="分配计算"
      :visible.sync="renyuanVisible"
      append-to-body
      :fullscreen="false"
    >
      <renyuanResults ref="renyuanResults"></renyuanResults>
    </el-dialog>
    <!--粗放式导入数据-->
    <el-dialog
      title="粗放式导入数据"
      :visible.sync="daoruVisible"
      append-to-body
    >
    <div style="overflow:hidden">
      <el-col :span="24">
        <el-table
            :data="tableList.tableData"
            border
            stripe
            ref="cutable"
            :summary-method="getSummaries"
            show-summary
            v-loading="daoruLoading"
          >
            <el-table-column
              v-for="(ele, index) in tableList.tableColumn"
              :key="index"
              header-align="center"
              align="center"
              :prop="ele.prop"
              :label="ele.label"
            >
            </el-table-column>
          </el-table>
      </el-col>
    </div>

    </el-dialog>
  </div>
</template>

<script>
import {
  fetchList,
  putObj,
  delObj,
  saveYjff,
  jjfpts,
  sendFP,
  sendFF,
  jiangjinFpApiSubmit,
  getJiangjinDataByImport,
  submitJJTaskt
} from "@/api/jiangjin/jiangjinfpjjfpdjb";
import jjimportDiaolg from './importjjDiaolg'
import TableForm from "./jiangjinfpjjfpdjb-form";
import TableFormTwo from "./jiangjinfpjjfpdjb-formTwo";
import jiangjinfpjjfpdjbYdjjForm from "./jiangjinfpjjfpdjb-ydjj-form";
import TableFormJjc from "./jiangjinfpjjfpdjb-jjc";
import TableFormJjcGl from "./jiangjinfpjjfpdjb-jjcgl";
import jiangjinfpjjfpdjbFp from "./jiangjinfpjjfpdjb-fp";
import jiangjinfpjjfpdjbHffpForm from "./jiangjinfpjjfpdjb-hffp-form";
import jiangjinfpjjfpdjbHffpNew from "./jiangjinfpjjfpdjb-hffp-new";
import jiangjinfpjjfpdjbRwfjForm from "./jiangjinfpjjfpdjb-rwfj-form";
import jiangjinfpjjfpdjbFf from "./viewFf";
import jiangjinfpjjfpdjbFileManager from "./jiangjinfpjjfpdjb-file-manager";
import workflow from "@/views/workflow/apply/index";
import jiangjinxinfpryfz from "@/views/jiangjin/jiangjinfpjjfpdjb/jiangjinxinfpryfz";
import jiangjinWork from "@/views/workflow/apply/jiangjinWork";
import fpcaozuo from "@/views/jiangjin/jiangjinfpjjfpdjb/xincaozuo/fpcaozuo";
import { getJiangJinBm } from "@/api/admin/dept";
import { list } from "@/api/workflow/wfflowconfig";
import { create } from "@/api/workflow/wfywmain";
//import UserCommonSelect from "@/views/hetongrenwu/components/usercomment-select";
import store from "@/store";
import { showMessage } from "@/api/activiti/task";
import { mapGetters } from "vuex";
import personCard  from "@/views/jiangjin/jiangjinfpjjfpdjb/xincaozuo/personCard";
import processTracking from "../jiangjinTemplate/processTracking";
import jigouResults from "@/views/jiangjin/jiangjinfpjjfpdjb/xincaozuo/jigouResults";
import renyuanResults from "@/views/jiangjin/jiangjinfpjjfpdjb/xincaozuo/renyuanResults";

var countdown=15;
export default {
  data() {
    return {
      headers: {
        Authorization: "Bearer " + store.getters.access_token,
      },
      hisTableData: [],
      actPicUrlList: [],
      actPicUrl: "",
      showPicDialog: false,
      deptId: "",
      deptbz: true,
      fzbmData: [],
      dataForm: {
        jjMc: "",
        fpZt: "",
        jjDeptId: "",
        jjDeptName: "",
        id:""
      },
      fpRow: {},
      formfp: {
        examineId: null,
      },
      formff: {
        examineId: null,
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      addOrUpdateVisible: false,
      addOrUpdateVisibleTwo: false,
      tableFormJjcVisible: false,
      tableFormJjcGlVisible: false,
      wfListfp: [],
      wfListff: [],
      fpspvisible: false,
      ffspvisible: false,
      ymLoad: false,
      tstype: "",
      fpId: "",
      isShow:true,
      importjjDiaolgData:{},
      jrContent:'发起奖金分配',
      jrType:'primary',
      mninnerVisible:false,
      renyuanVisible:false,
      tableList:{},
      daoruVisible:false,
      daoruLoading:false,
      isJjfp:true,
      taskId:"",
      taskFlag:"",
      processId:""
    };
  },
  components: {
    TableForm,
    jiangjinfpjjfpdjbFp,
    jiangjinfpjjfpdjbFf,
    jiangjinfpjjfpdjbFileManager,
    jiangjinfpjjfpdjbYdjjForm,
    jiangjinfpjjfpdjbHffpForm,
    jiangjinfpjjfpdjbHffpNew,
    jiangjinfpjjfpdjbRwfjForm,
    TableFormJjc,
    TableFormJjcGl,
    workflow,
    jiangjinxinfpryfz,
    jiangjinWork,
    fpcaozuo,
    //UserCommonSelect,
    TableFormTwo,
    jjimportDiaolg,
    personCard,
    processTracking,
    jigouResults,
    renyuanResults
  },
  props:{
    tabType:{
      type:String,
      default:'jigou'
    }
  },
  created() {
    if(this.$route.query.id){
      this.$set(this.dataForm,'id',this.$route.query.id)
    }
    if(this.tabType=='jigou'){
      this.jrContent='发起奖金分配'
      this.jrType='primary'
    }else{
      this.jrContent='二级领导发起'
      this.jrType='warning'
    }
    let date=new Date;
    let months=date.getMonth()+1;
    if(months<10){
      months='0'+months
    }else{
      months=months
    }
    this.$set(this.dataForm,'months',months)
  },
  mounted() {
    this.getJiangJinJg();
  },
  computed: {
    ...mapGetters(["permissions"]),
  },
  methods: {
    //通过
    onPass(row,type){
      this.fpId=row.id
      this.processId=row.processId
      this.taskId=row.taskId //审批id
      this.tstype = 'sptg'; //审批通过
      this.taskFlag=type
      this.isJjfp=true
      this.$nextTick(() => {
        this.$refs.usercomment.init("12", "allTree", "", "htcj",'通过');
      });
    },
    //驳回
    onRejected(row,type){
      var param={
        taskId:row.taskId,
        taskFlag:type,
        fpId:row.id,
        type:"JJ_FF",
        processId:row.processId,
      }
      submitJJTaskt(param).then(res=>{
        if(res.data.code==0){
          this.$message.closeAll()
          this.$message.success("驳回成功");
          this.getDataList();
        }
        })
    },
    //机构计算结果
    jigouTan(id){
      this.mninnerVisible = true;
      this.$nextTick(() => {
        this.$refs.jigouResults.init(id, "jg", "缩小");
      });
    },
    //人员计算结果
    renyuanTan(id){
      this.renyuanVisible = true;
        this.$nextTick(() => {
          this.$refs.renyuanResults.init(id, "ry", "缩小",'首页',false);
        });
    },
    //点击奖金名称
    faqiDetail(row){
      this.daoruVisible=true
      this.daoruLoading=true
        getJiangjinDataByImport(row.id).then(res=>{
          if(res.data.data){
            this.tableList.tableColumn=res.data.data.tableColumn
            this.tableList.tableData=res.data.data.tableData
            this.$forceUpdate()
            this.daoruLoading=false
          }else{
            this.tableList.tableColumn=[]
            this.tableList.tableData=[]
            this.daoruLoading=false
          }

        })
      // if(row.importflag==1){
      //   this.addOrUpdateVisibleTwo = true;
      //   this.$nextTick(() => {
      //     this.$refs.addOrUpdateTwo.xiangqing(row.id);
      //   });
      // }else{
      //   this.$message.closeAll()
      //   this.$message.warning('该数据不是导入数据!')
      // }
    },
    // 总计表统计 tableData tableColumn
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "总计";
          return;
        }

        const values = data.map((item) => Number(item[column.property]));
        if (!values.every((value) => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          if (index === 1) {
            sums[index] += "人";
          } else {
            sums[index] += " 元";
          }
        } else {
          sums[index] = "N/A";
        }
      });
      return sums;
    },
    //调整中提交
    dzti(row,type){
      this.proId=row.processIdFf
      this.tstype=type
      this.isJjfp=false
      this.$nextTick(() => {
        this.$refs.usercomment.init("12", "allTree", "", "htcj",'提交');
      });
    },
    showMessage(proId, row) {
      this.$refs.processTracking.init(proId);
    },

    // showMessage(proId) {
    //
    //   showMessage(proId).then((res) => {
    //     this.hisTableData = res.data.data;
    //     //console.log(res.data.data)
    //   });
    //   this.actPicUrl = `/act/sp/view/` + proId;
    //
    //   this.actPicUrlList = [];
    //   this.actPicUrlList.push(`/act/sp/view/` + proId);
    //   this.showPicDialog = true;
    // },
    // 奖金分配
    importjjBtn(){
      this.importjjDiaolgData ={
        visible:true,
        showTab:'all',
        activeName:this.tabType
      }
    },
    //新分配子集
    jiangjinxinChild(jiangjinxinChild) {},
    //管理部门切换
    switchDepartment(deptId) {
      this.dataForm.jjDeptId = deptId;
      //deptName
      this.fzbmData.forEach(item=>{
        if(item.deptId==deptId){
          this.dataForm.deptName=item.deptName
        }
      })
    },
    // 确认发放月奖
    dataFormSubmit(id) {
      this.$confirm("是否确认执行？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        saveYjff(id)
          .then((data) => {
            this.$notify.closeAll();
            this.$notify.success("操作成功");
            this.getDataList();
          })
          .catch(() => {
            this.$notify.closeAll();
            this.$notify.error("操作失败");
          });
      });
    },
    //获取奖金管理人机构
    getJiangJinJg() {
      getJiangJinBm()
        .then((res) => {
          if (res.data.data != null && res.data.data.length > 0) {
            this.fzbmData = res.data.data;
            this.dataForm.deptName=this.fzbmData[0].deptName
            this.ymLoad = false;
            this.deptId = "";
            this.deptbz = true;
            var ids = [];
            for (var a in this.fzbmData) {
              ids.push(this.fzbmData[a].deptId);
            }
            this.dataForm.jjDeptName = ids.join(",");
            this.getDataList();
          } else {
            this.deptbz = false;
            this.ymLoad = true;
            //this.$notify.closeAll();
            //this.$notify.error("没有相关负责部门")
          }
        })
        .catch((err) => {
          this.ymLoad = true;
        });
    },
    // 获取数据列表
    getDataList(page) {
      if (page) {
        this.pageIndex = page;
      }
      this.$refs.table.clearSelection();
      this.dataListLoading = true;
      fetchList(
        Object.assign(
          {
            current: this.pageIndex,
            size: this.pageSize,
          },
          this.dataForm
        )
      ).then((response) => {
        var data = response.data.data.records;
        for (var i in data) {
          data[i].jjxList = JSON.parse(data[i].jjxXq);
        }
        this.dataList = data;
        this.totalPage = response.data.data.total;
        this.dataListLoading = false;
      });

    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    //  修改
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true;
      //addOrUpdateVisibleTwo
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id, "编辑");
      });
    },
    //新增
    addOrUpdateHandleTwo() {
      this.addOrUpdateVisibleTwo = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdateTwo.init("", "新增");
      });
    },
    //分配提审
    tsJjfp(row, type) {
      this.fpId = row.id;
      this.tstype = type;
      this.isJjfp=true
      this.$nextTick(() => {
        this.$refs.usercomment.init("12", "allTree", "", "htcj",'提交审核');
      });
    },
    //发放提审
    tsJjff(row, type) {
      this.fpId = row.id;
      this.tstype = type;
      this.isJjfp=true
      this.$nextTick(() => {
        this.$refs.usercomment.init("12", "allTree", "", "htcj",'发放提审');
      });
    },
    submitfy(data) {

      var ids = "";
      data.tableDataUser.forEach((ele) => {
        ids = ids + ele.userId + ",";
      });

      var params = {
        fpId: this.fpId,
        userList: ids,
      };

      if (this.tstype == "fpts") {

        sendFP(params).then((res) => {
          this.$message.closeAll()
          this.$message.success("提交审核成功");
          this.getDataList();
        });
      }else if(this.tstype == "dztj"){
       var obj={
              proId:this.proId,
              userList:ids
            }
            jiangjinFpApiSubmit(obj).then(res=>{
              this.$message.closeAll()
              this.$message.success("提交成功!")
              this.getDataList(1)
          })

      } else if(this.tstype =='sptg'){
        //通过
        var can={
          taskId:this.taskId,
          taskFlag:this.taskFlag,
          userlistSj:ids,
          fpId: this.fpId,
          type:"JJ_FF",
          processId:this.processId,
          key:'key'
        }
        submitJJTaskt(can).then(res=>{
          this.$message.closeAll()
          this.$message.success("通过成功");
          this.getDataList();
        })
      }else {
        var paramses={
          fpId: this.fpId,
          userList: ids,
          pd:data.formRen.isFs,
          asssj:data.formRen.userId,
        }
        sendFF(paramses).then((res) => {
          this.$message.closeAll()
          this.$message.success("发放提审成功");
          this.getDataList();
        });
      }
      // data.tableDataUser;
    },
    tjfpsptj() {
      //提交内容验证
      this.$refs["fpform"].validate((valid) => {
        if (valid) {
          this.fpspvisible = false;
          //建立审批
          let cr = {
            flowId: this.formfp.examineId,
            ywLyid: this.fpRow.id,
            ywTitle: this.fpRow.jjMc,
            ywType: "jjfp",
          };
          create(cr).then((res) => {
            //更新数据
            let nf = {
              id: this.fpRow.id,
              examineId: this.formfp.examineId,
              mainId: res.data.data.id,
              fpZt: "审批中",
            };
            putObj(nf).then((ress) => {
              //刷新列表
              this.getDataList();
              //打开审批
              this.$refs.workflow.open(res.data.data.id);
            });
          });
        }
      });
    },
    //分页序号递增
    nShowIndex(row, column, cellValue, index) {
      return index + 1 + this.pageSize * (this.pageIndex - 1);
    },
    //查看奖金
    viewJjfp(r) {
      // console.log(JSON.stringify(r));
      this.$nextTick(() => {
        //this.$refs.workflow.open(r.mainId);
        this.$refs.jiangjinWork.open(r.id, r.taskId, null, null, "详情");
      });
    },
    //恢复分配
    viewHffp(r) {
      this.$nextTick(() => {
        // this.$refs.jiangjinfpjjfpdjbHffpForm.init(r.id);
        this.$refs.jiangjinfpjjfpdjbHffpNew.init(r.id,this.dataForm.deptName);
      });
    },

    tjffsptj() {
      //提交内容验证
      this.$refs["ffform"].validate((valid) => {
        if (valid) {
          this.ffspvisible = false;
          //建立审批
          let cr = {
            flowId: this.formff.examineId,
            ywLyid: this.fpRow.id,
            ywTitle: this.fpRow.jjMc,
            ywType: "jjff",
          };
          create(cr).then((res) => {
            //更新数据
            let nf = {
              id: this.fpRow.id,
              examineIdFf: this.formff.examineId,
              mainIdFf: res.data.data.id,
              ffZt: "审批中",
            };
            putObj(nf).then((ress) => {
              //刷新列表
              this.getDataList();
              //打开审批
              this.$refs.workflow.open(res.data.data.id);
            });
          });
        }
      });
    },
    //查看奖金
    viewJjff(r) {
      console.log(r);
      this.$nextTick(() => {
        this.$refs.workflow.open(r.mainIdFf, r.taskId, r.id);
      });
    },

    //最新分配操作
    xinJiangTwo() {
      var data = this.$refs.table.selection[0];
      if(this.$refs.table.selection.length==0){
        this.$message.closeAll()
        this.$message.warning("请勾选一条可以奖金分配得数据")
      }else if((data.fpZt == '分配中'||data.fpZt == '调整中')&& this.$refs.table.selection.length==1){
        this.$nextTick(() => {
          this.$refs.fpcaozuoRef.init(data,this.tabType);
        });
      }else{
        this.$message.closeAll()
        this.$message.warning("请勾选一条可以奖金分配得数据")
      }


    },
    //新奖金分配
    xinJiang(row) {
      this.$nextTick(() => {
        this.$refs.jiangjinxinfpryfzForm.init(row);
      });
    },
    // 奖金分配
    openJjfp(id) {
      this.$nextTick(() => {
        this.$refs.jiangjinfpjjfpdjbFp.init(id);
      });
    },
    // 奖金发放
    openJjff(row) {
      var id;
      if(row.ffZt == '上级领导审批中'||row.ffZt == '上级审批中'||row.ffZt == '审批完成'){
        id=row.copyId
      }else{
        id=row.id
      }
      this.$nextTick(() => {
        this.$refs.jiangjinfpjjfpdjbFf.init(id);
      });
    },
    fjgl(id) {
      console.log(id);
      this.$nextTick(() => {
        this.$refs.jiangjinfpjjfpdjbFileManager.init(id);
      });
    },
    // 月度奖金
    openYdjj(id) {
      this.$nextTick(() => {
        this.$refs.jiangjinfpjjfpdjbYdjjForm.init(id);
      });
    },
    //任务分解
    fenjieHandle(r) {
      this.$refs.jiangjinfpjjfpdjbRwfjForm.init(r);
    },
    // 删除
    deleteHandle(id) {
      var data=this.$refs.table.selection
      if(data.length==0){
        this.$message.closeAll()
        this.$message.warning('请选择一条要删除的数据！')
        return false
      }
      if(data.length>1){
        this.$message.closeAll()
        this.$message.warning('只能选择一条要删除的数据！')
        return false
      }
      if(data.length==1){
        if(data[0].fpZt == '分配中' &&!(data[0].ffZt == '审批中' || data[0].ffZt == '审批通过') && data[0].pid == 0){
          this.$confirm("删除后不可恢复，是否执行！", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(function () {
              return delObj(data[0].id);
            })
            .then((data) => {
              this.$message.closeAll()
              this.$message.success("删除成功");
              this.getDataList();
            });
        }else{
          this.$message.closeAll()
          this.$message.warning('该条数据不能删除!')
        }
      }

    },
    //机构奖金池
    openJjc() {
      this.tableFormJjcVisible = true;
      this.$nextTick(() => {
        this.$refs.tableFormJjc.init(this.dataForm.jjDeptName);
      });
    },
    //奖金池管理
    jjcManage() {
      this.tableFormJjcGlVisible = true;
      this.$nextTick(() => {
        this.$refs.tableFormJjcGl.init(this.dataForm.jjDeptName);
      });
    },
    //状态
    Zt(value) {
      return {
        red: value === "审批中",
        green: value === "审批通过",
        yellow:value === "调整中",
      };
    },
  },
};
</script>
<style scoped>
.form-inline {
  margin-bottom: 0px !important;
}
.bg .el-image-viewer__mask {
  background-color: white;
  opacity: 1;
}
.yellow{
  color: #FFA500;
}
</style>
